home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PACKET / CBBS60SO.ZIP / HAND.ASM < prev    next >
Assembly Source File  |  1988-11-11  |  6KB  |  255 lines

  1. ;  HAND.ASM  10/26/88
  2.  
  3. ;  Manager for common share of data between mailboxes.
  4.  
  5. ;  Call with port number (15) in DL.
  6. ;  Flags are sent or returned in AH.
  7. ;  Commands are sent and returned in BX.
  8.  
  9.  
  10. everything SEGMENT PUBLIC
  11.  
  12.       ASSUME CS: everything           ; These assumptions are for the
  13.       ASSUME DS: everything           ; assembler's benefit.  The code
  14.       ASSUME ES: nothing              ; jerks things around as it pleases
  15.       ASSUME SS: nothing
  16.  
  17. ; Program start and buffer declares
  18.  
  19.           ORG     100H
  20. foo:      JMP     start               ; Entry point
  21.  
  22.  
  23. ; Area where things are declared
  24.  
  25. comnumber  db     15                  ; Comm number - Port P
  26. portflag   db     0
  27. cmdflag    db     0                   ; Command flag
  28. busyflag   db     0                   ; Busy flag
  29. command    dw     0
  30.  
  31. ; Static variables
  32.  
  33. old_bios_vector   dw  ?               ; Save previous interrupt vector
  34.                   dw  ?
  35.  
  36. ; Our BIOS handler
  37.  
  38. rsint:
  39.  
  40.         ASSUME DS: NOTHING         ; Don't use DS
  41.         ASSUME ES: NOTHING         ; Don't use ES
  42.         ASSUME SS: NOTHING         ; Don't use SS
  43.  
  44. ; See if this is our vector.
  45.  
  46.         push    bp
  47.         cmp     dl,cs:comnumber     ; Source port?
  48.         je      ours                ; Yes...
  49.  
  50. ;  Source port not found. Call next handler
  51.  
  52.         pop     bp
  53.         jmp     cs:dword ptr old_bios_vector
  54.  
  55. ours:
  56.         push    cx
  57.         push    dx
  58.  
  59.         or      ah,ah               ; 0
  60.         je      init_jmp            ; Initialize.
  61.  
  62.         dec     ah
  63.         dec     ah
  64.         dec     ah
  65.         dec     ah                  ; 4
  66.         jz      inquiry_jmp         ; Inquiry?
  67.  
  68.         dec     ah
  69.         dec     ah
  70.         dec     ah
  71.         dec     ah                  ; 8
  72.         jz      fuct_8_jmp              ; Set busy.
  73.  
  74.         dec     ah                  ; 9
  75.         jz      fuct_9_jmp              ; Clear busy.
  76.  
  77.         dec     ah                  ; 10
  78.         jz      fuct_10             ; Put portflag.
  79.  
  80.         dec     ah                  ; 11
  81.         jz      fuct_11             ; Put cmdflag.
  82.  
  83.         dec     ah                  ; 12
  84.         jz      fuct_12             ; Get portflag.
  85.  
  86.         dec     ah                  ; 13
  87.         jz      fuct_13             ; Get cmdflag
  88.  
  89.         dec     ah                  ; 14
  90.         jz      fuct_14             ; Get Command.
  91.  
  92.         dec     ah                  ; 15
  93.         jz      fuct_15             ; Put Command.
  94.  
  95.         jmp     fuct_exit           ; Unknown function, ignore.
  96.  
  97. init_jmp:
  98.         jmp     init
  99.  
  100. inquiry_jmp:
  101.         jmp     inquiry
  102.  
  103. fuct_8_jmp:
  104.         jmp     fuct_8
  105.  
  106. fuct_9_jmp:
  107.         jmp     fuct_9
  108.  
  109.  
  110. ;  Call with DL = port number. Fill portflag with AL.
  111.  
  112. fuct_8:
  113.         or      busyflag,al           ; Set busy flag.
  114.         jmp     fuct_exit
  115.  
  116. fuct_9:
  117.         xor     al,11111111B          ; Complement al.
  118.         and     busyflag,al           ; Clear busy flag.
  119.         jmp     fuct_exit
  120.  
  121. fuct_10:
  122.         mov     portflag,al            ; Into portflag
  123.         jmp     fuct_exit
  124.  
  125.  
  126. ;  Call with DL = port number. Fill cmd flag with BL.
  127.  
  128. fuct_11:
  129.         mov     cmdflag,bl            ; Into cmdflag.
  130.         jmp     fuct_exit
  131.  
  132.  
  133. ;  Call with DL = port number. Return portflag in AL.
  134.  
  135. fuct_12:
  136.         mov     al,portflag            ; portflag out.
  137.         jmp     fuct_exit
  138.  
  139.  
  140. ;  Call with DL = port number. Return cmd-busy flag in BX.
  141.  
  142. fuct_13:
  143.         mov     bl,cmdflag            ; cmdflag out.
  144.         mov     bh,busyflag           ; busyflag out.
  145.         jmp     fuct_exit
  146.  
  147. fuct_14:
  148.         mov     bx,command            ; Get command.
  149.         jmp     fuct_exit
  150.  
  151. fuct_15:
  152.         mov     command,bx            ; Put command.
  153.         jmp     fuct_exit
  154.  
  155.  
  156. ;  Reset flags to zero.
  157.  
  158. init:
  159.         mov     ax,0
  160.         mov     portflag,al         ; Set flag1 to zero.
  161.         mov     busyflag,al         ; Set busyflag to zero.
  162.         mov     cmdflag,al          ; Set flag2 to zero.
  163.         mov     command,ax          ; Set command to zero.
  164.         jmp     fuct_exit
  165.  
  166.  
  167. ;  Return AA55H in ax - To tell if driver is loaded.
  168.  
  169. inquiry:
  170.         mov     ax,0AA55h
  171.         jmp     fuct_exit
  172.  
  173. ; Interrupt exit.
  174.  
  175. fuct_exit:
  176.  
  177.         pop     dx                  ; Restore registers.
  178.         pop     cx
  179.         pop     bp
  180.         sti                         ; Turn interrupts back on
  181.         iret                        ;      and leave
  182.  
  183. program_end:
  184.  
  185.  
  186. ; Main line to initialize.
  187.  
  188.       ASSUME DS: everything
  189.  
  190. ; Constants only needed by initialization
  191.  
  192. cr      equ     0dh
  193. lf      equ     0ah
  194.  
  195. hello   db      cr,lf
  196.         db      'HAND device driver 1.3, OCTOBER 26, 1988', cr, lf, '$'
  197.  
  198. bye     db      cr,lf
  199.         db      'Driver Installed OK.',cr,lf,'$'
  200.  
  201. loaded  db      'Already Loaded.', cr, lf, '$'
  202.  
  203. ; Initialize routine
  204.  
  205. start:  mov     ax,cs                 ; Point DS in the right place
  206.         mov     ds,ax
  207.  
  208.         lea     dx,hello              ; Print signon message
  209.         mov     ah,9
  210.         int     21h
  211.  
  212.         mov     dx,15                 ; Check to see if support already loaded
  213.         mov     ah,04
  214.         int     14h
  215.         cmp     ax,0AA55h
  216.         jz      exit                  ; Must be loaded
  217.  
  218. ; Now snatch the BIOS comm vector  (Int 14)
  219.  
  220.         mov     al,14h
  221.         mov     ah,35h
  222.         int     21h
  223.         mov     old_bios_vector,BX     ;      save old vector
  224.         mov     old_bios_vector+2,ES
  225.  
  226.         mov     dx,offset rsint         ; Replace with our vector
  227.         mov     al,14h
  228.         mov     ah,25h
  229.         int     21h
  230.  
  231.  
  232.         lea     dx,bye                 ; Print signoff message
  233.         mov     ah,9
  234.         int     21h
  235.  
  236.         mov     al,0                   ; set exit code
  237.         mov     dx,offset program_end
  238.         mov     cl,4
  239.         shr     dx,cl
  240.         inc     dx
  241.         mov     ah,31h
  242.         int     21h                    ; Terminate but stay resident
  243.  
  244. exit:   lea     dx,loaded
  245.         mov     ah,9
  246.         int     21h
  247.         mov     al,0                   ; set exit code = Ok
  248.         mov     ah,4ch
  249.         int     21h                    ; Terminate and return
  250.  
  251.  
  252. everything ENDS
  253.  
  254.         END foo
  255.